HIVE常用正则函数(like、rlike、regexp、regexp

您所在的位置:网站首页 hive regexp_extract函数详解 HIVE常用正则函数(like、rlike、regexp、regexp

HIVE常用正则函数(like、rlike、regexp、regexp

2024-02-24 11:58| 来源: 网络整理| 查看: 265

Oralce中regex_like和hive的regexp对应

select regexp_like('JFAF','^[JKN]') -- 以J或K或N开头 -- oracle,impala语法

select 'JFAF' regexp '^[JKN]'; -- hive语法

LIKE

语法1: A LIKE B

语法2: LIKE(A, B)

操作类型: strings

返回类型: boolean或null

描述: 如果字符串A或者字符串B为NULL,则返回NULL;如果字符串A符合表达式B的正则语法,则为TRUE;否则为FALSE。B中字符"_"表示任意单个字符,而字符"%"表示任意数量的字符。

hive>select'football' like '%ba';OKfalse hive>select'football' like '%ba%';OKtrue hive>select'football' like '__otba%';OKtrue hive>selectlike('football','__otba%');OKtrue RLIKE

语法1: A RLIKE B

语法2: RLIKE(A, B)

操作类型: strings

返回类型: boolean或null

描述: 如果字符串A或者字符串B为NULL,则返回NULL;如果字符串A符合JAVA正则表达式B的正则语法,则为TRUE;否则为FALSE。

hive>select'football' rlike 'ba';OKtrue hive>select'football' rlike '^footba';OKtrue hive>selectrlike('football','ba');OKtrue Java正则:

"." 任意单个字符

"*" 匹配前面的字符0次或多次

"+" 匹配前面的字符1次或多次

"?" 匹配前面的字符0次或1次

"\d" 等于 [0-9],使用的时候写成'\d'

"\D" 等于 [^0-9],使用的时候写成'\D'

hive>select'does' rlike 'do(es)?';OKtrue hive>select'\\'; OK \ hive>select'2314' rlike '\\d+';OKtrue REGEXP 语法1:AREGEXP B 语法2:REGEXP(A, B) 操作类型: strings 返回类型: boolean或null 描述: 功能与RLIKE相同 hive>select'football' regexp 'ba';OKtrue hive>select'football' regexp '^footba';OKtrue hive>selectregexp('football','ba');OKtrue 语法:regexp_replace(string A,string B,string C) 操作类型: strings 返回值:string 说明: 将字符串A中的符合java正则表达式B的部分替换为C。 hive>selectregexp_replace('h234ney','\\d+','o');OK honey REGEXP_REPLACE

语法: regexp_replace(string A, string B, string C)

操作类型: strings

返回值: string

说明: 将字符串A中的符合java正则表达式B的部分替换为C。

hive>selectregexp_replace('h234ney','\\d+','o');OK honey REGEXP_EXTRACT

语法: regexp_extract(string A, string pattern, int index)

返回值: string

说明:将字符串A按照pattern正则表达式的规则拆分,返回index指定的字符,index从1开始计。

hive>selectregexp_extract('honeymoon','hon(.*?)(moon)',0);OK honeymoon hive>selectregexp_extract('honeymoon','hon(.*?)(moon)',1);OK ey hive>selectregexp_extract('honeymoon','hon(.*?)(moon)',2);OK moon

作者:多彩海洋

链接:https://www.jianshu.com/p/3bcc06b1294b

来源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3